package com.juku2024.juku.adapter

import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.db.entity.VideoEntity
import com.juku2024.juku.tools.AppUtils
import com.juku2024.juku.tools.Constants
import com.juku2024.juku.tools.ImageUtils
import java.util.*

class SearchResultAdapter(data: ArrayList<VideoEntity>) :
    BaseQuickAdapter<VideoEntity, BaseViewHolder>(R.layout.item_search_result, data), LoadMoreModule {

    init {
        addChildClickViewIds(R.id.btnPlay)
    }

    override fun convert(holder: BaseViewHolder, item: VideoEntity) {
        val name = item.name?:""
        holder.setText(R.id.tvSearchResultName, name)

        val iv = holder.getView<ImageView>(R.id.ivSearchResult)
        ImageUtils.loadImage(iv, item.pic)

        if (item.category == Constants.VIDEO_CATEGORY_MOVIE) {
            //电影显示评分
            if (item.score > 0) {
                holder.setText(R.id.tvSearchResultYear, item.score.toString())
                    .setTextColor(R.id.tvSearchResultYear, AppUtils.getColor(R.color.cFF6D2F))
            }
        } else {
            //其他显示更新进度
            if (!TextUtils.isEmpty(item.update_progress)) {
                holder.setText(R.id.tvSearchResultYear, item.update_progress)
                    .setTextColor(R.id.tvSearchResultYear, AppUtils.getColor(R.color.c9C9C9C))
            }
        }

        val ivShortPlays = holder.getView<ImageView>(R.id.iv_short_plays)
        val visibility = if (item.sp) {
            View.VISIBLE
        } else {
            View.GONE
        }
        ivShortPlays.visibility = visibility
    }

}